home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / AUDIOPLAYERS / AMPLAYER / !Amplayer / !Help < prev    next >
Text File  |  1999-05-22  |  17KB  |  467 lines

  1.  
  2.                                     AMPlayer
  3.                                     --------
  4.  
  5.  
  6. This is a module for playing Audio MPEG files through the computer sound
  7. output. It will select the 8 or 16 bit output depending on the normal
  8. configuration (and availability).
  9. The frontend, !AMPlayer, doesn't do much in itself, apart from providing an
  10. interface to the module from the desktop.
  11. The module has been designed so it is easy to make other frontends, or add
  12. support for the module to existing player-frontends.
  13.  
  14.  
  15. !AMplayer frontend
  16. ==================
  17.  
  18. The frontend is mainly included as an example of how to make your own.
  19. It consists of a display and control part. There is no link between these
  20. two parts (with one exception: Counter mode). It might as well be two
  21. separate programs. The control part simply issues commands and SWIs to the
  22. player module. The display part presents the current state of the module.
  23. This means that any commands issued by something else (e.g. you) will also
  24. cause the display to react in exactly the same way, as if the operation had
  25. been performed using the controls.
  26.  
  27.  
  28. Control
  29. -------
  30.  
  31. The frontend is very simple, and behaves more or less like a normal tape deck.
  32. Dragging an AMPEG file to the window (or double-clicking on one) will ask the
  33. module to play it. The buttons below the display behaves like one would
  34. expect:
  35.  
  36. "Stop" will stop the playback.
  37.  
  38. "Play" is used to continue after pausing.
  39.  
  40. "Pause" stops playback, with the option of continuing from that point.
  41.  
  42. "Rewind" and "Fast forward" skips back and forth in the track. The sound
  43. quality while doing this may vary a lot, especially if the file is coming
  44. from a slow medium (e.g. a CD). Using these buttons while paused is preferable
  45. in these cases.
  46.  
  47. "Counter mode" toggles between display of elapsed, total, and remaining time.
  48. With some rare mpeg files, this may be inaccurate (see note about File Info
  49. Block below).
  50.  
  51. "Volume +/-" changes the overall volume. Some files will clip of this is set
  52. higher than -2 dB. If you suffer from clipping noise, lower it.
  53.  
  54. Another control function of !AMPlayer is, that if you hold shift while
  55. dragging in a file, it will be put on hold (and "QUEUE" will show). When the
  56. current file finished, playback continues with the one dragged in. There
  57. can be only one file on queue at any time, so dragging in more files like this
  58. will just end up with the last one on hold. Some day this might change, who
  59. knows.
  60. Similarily, holding shift while clicking Stop, will only stop the current
  61. file, and continue with a queued one if any.
  62.  
  63. "Auto Queue": When playing a file, the directory is scanned, and the next
  64. file is automatically queued. If a directory is met, this is scanned too.
  65. When there are no more files in the directory, the scan is continued in the
  66. parent. When no file can be found, Auto Queue enters a "dormant" state (with
  67. the indicator flashing). If you play a new file in this state, the scan will
  68. be resumed from that file and onwards.
  69.  
  70. So, this scanning would take some time if there are lots of directories left,
  71. but no mpeg files at all. For this reason, it will skip a maximum of 30 files,
  72. then give up. At some point this limit will be user-defined.
  73. For various reasons, this scanning will not look for files of type AMPEG, but
  74. rather of the same type as was played last time. This is most useful on CDs,
  75. where the type-map isn't set up and the files are all reported as type Data.
  76.  
  77.  
  78. Display
  79. -------
  80.  
  81. Most of the display is fairly self-explanatory. The textual part can show
  82. various things:
  83. If the file contains a valid ID3 tag, the song title and artist are shown.
  84. If not, the leafname is shown. If an error occurs while decoding the stream,
  85. it will be displayed for a few seconds in place of the artist.
  86.  
  87.  
  88. AMPlayer module
  89. ===============
  90.  
  91. This is the program that does the actual work. There are various reasons for
  92. wanting to control the module directly instead of through the frontend:
  93. 1. You get better control, and can automate things using obey files, etc.
  94. 2. You may want to write your own frontend.
  95. 3. The fancy frontend uses memory and CPU time that might be better used
  96.    elsewhere.
  97.  
  98. For these purposes, the module has several *commands and SWIs.
  99.  
  100. * Commands
  101. ==========
  102.  
  103. *AMPlay starts playing an Audio MPEG file. When -Q[ueue] is present, the file
  104. will be played after the current one finishes, otherwise immediately.
  105. When -C[ue] is present, the file will be started, but with the player in pause
  106. mode.
  107. Syntax: *AMPlay [-Queue|-Cue] <filename>
  108.  
  109. *AMStop stops the MPEG file playing
  110. Syntax: *AMStop
  111.  
  112. *AMInfo prints information about the player module status, and about the file
  113. playing, if any.
  114. Syntax: *AMInfo
  115.  
  116. *AMVolume sets the playback volume. Range is 0 to 127, with 113 as initial
  117. value.
  118. Syntax: *AMVolume <number>
  119.  
  120. *AMLocate locates the specified point in the file currently playing/paused.
  121. Syntax: *AMLocate <hours>[:<minutes>[:<seconds>]]
  122.  
  123.  
  124. System variables
  125. ================
  126.  
  127. AMPlayer$Buffer$*
  128. -----------------
  129. You can set up the audio buffer size to use by setting one or more of these
  130. variables. When the buffer is created, the size is determined by the best
  131. match of the filename and one of these variables. The more characters that
  132. match, the better, and the variable with the most will control the buffer
  133. size.
  134. The idea is that the best buffer size somewhat depends on the file access
  135. speed. The faster the device, the smaller buffer you can get away with, and
  136. the better response you will get from things like fast forward/rewind.
  137. CDFS for example is very slow. Therefore, I have the following variables:
  138. AMPlayer$Buffer$    20
  139. AMPlayer$Buffer$SCSI    16
  140. AMPlayer$Buffer$CDFS    40
  141.  
  142. The effect of this is, that CDFS in general will get size 40. SCSI is fast
  143. and gets 16, and everything else (ADFS, RAMFS etc.) get 20.
  144. It is possible (but not necessary in my case) to include part of the disc
  145. name too (e.g. "AMPlayer$Buffer$ADFS::Winnie"), to make the buffer size
  146. depend on the drive as well as the FS. Indeed, you can go further and
  147. include some directory path as well, though that will probably be rarely
  148. used (with softlinks perhaps?).
  149.  
  150. The size is given in "blocks". These are currently about 4.5K. The reason
  151. for not giving it in Kbytes is, that it is highly likely that the buffer
  152. requirement will change (decrease) in later versions, while still having
  153. the same resulting buffer time. Giving it in blocks means you don't have
  154. to change the value when the block size changes.
  155.  
  156.  
  157. AMPlayer$FileBuffer
  158. -------------------
  159. If this variable is set, it is used to decide the size of the input buffer.
  160. On slow filing systems, the sound may mute while fetching more data. Raising
  161. the input buffer size will help. The size is given in kbytes. If the variable
  162. doesn't exist, the default size is 32K.
  163.  
  164.  
  165. AMPlayer$Volume
  166. ---------------
  167. Setting this to some value between 0 and 127, will determine the default
  168. volume when the module is later loaded. It only has effect before loading;
  169. to change the volume afterwards, use *AMVolume.
  170. If unset, volume 113 is used at startup.
  171.  
  172.  
  173. SWI calls
  174. =========
  175.  
  176. SWI AMPlayer_Play
  177. -----------------
  178. On entry    R0 = Flags
  179.              bit0    Queue only
  180.              bit1    Cue
  181.         R1 ->Filename
  182.  
  183. On exit        All registers preserved
  184.  
  185. Bit0,1 of R0 determines the action:
  186. 0    Starts playing the file immediately, after stopping any other file
  187.     currently playing.
  188. 1    Registers the filename as "next" file (see File info block below).
  189.     The file will start when the current one finishes normally (i.e. not
  190.     if it is stopped by an explicit call to AMPlayer_Stop or *AMStop).
  191.     If there is no file currently playing, the behaviour is exactly as
  192.     with bit0 of R0 clear.
  193. 2    Starts the file immediately, but frozen at frame 0 in pause mode.
  194.     Use SWI AMPlayer_Pause to start playback (which will start with a
  195.     very much shorter delay than if just using Play).
  196. 3    Currently undefined.
  197.  
  198. Note: There can only be one "next" file at any moment. The name registered
  199.       can safely be changed to something else, just by calling this SWI again.
  200.       It is possible to cancel the registered file by calling this SWI with
  201.       bit0 of R0 set, and R1 pointing to a null string.
  202.  
  203. Note: Given sufficient playback buffer and medium access speed, the current
  204.       file will continue seamlessly into the next one. This is good for live
  205.       music, that has been divided into separate files.
  206.  
  207.  
  208. SWI AMPlayer_Stop
  209. -----------------
  210. On entry    R0 = Flags
  211.              bit0    Cut to next file
  212.  
  213. On exit        All registers preserved
  214.  
  215. Stops playback. If bit0 of R0 is set, playback continues with a queued file
  216. if any.
  217.  
  218.  
  219. SWI AMPlayer_Pause
  220. ------------------
  221. On entry    R0 = Flags
  222.              bit0    Continue
  223.  
  224. On exit        All registers preserved
  225.  
  226. Action is determined by bit0 of R0:
  227. 0    Halts playback immediately.
  228. 1    Continues playback immediately.
  229.  
  230. Pause mode may also be cancelled by stopping. If Stop is used to cut to the
  231. next file, or if a different file is started, pause mode will continue to
  232. be in effect, freezing the new file at time=0. This can be used to ensure
  233. that playback starts at the instant of calling AMPlayer_Pause (as opposed to
  234. calling AMPlayer_Play, which can have a delay while opening the file etc.)
  235.  
  236.  
  237. SWI AMPlayer_Locate
  238. -------------------
  239. On entry    R0 = Flags
  240.         R1 = Target time
  241.  
  242. On exit        All registers preserved
  243.  
  244. Locates the position of the target time, and continues playback (or pausing)
  245. from there.
  246. This has no effect unless the status is either Playing, Locating or Paused.
  247. This may take some time, and the playback buffer may empty (which will mute
  248. the sound).
  249. The time given here corresponds to the elapsed time returned from
  250. AMPlayer_Info below. This is true even when the elapsed time is wrong (see
  251. below). So when, at time X, the Info call returns the wrong time Y, giving
  252. time Y to this call will still start playing at the right time X.
  253. Playback can only start on a frame boundary, so the resolution of the start
  254. point is around 2 cs (for 128kbit/sec, 44.1kHz frames).
  255.  
  256.  
  257. SWI AMPlayer_Info
  258. -----------------
  259. On entry    R0 = Flags
  260.  
  261. On exit        R0 = Player status
  262.         Other registers depend on status, as follows:
  263.             Status        Info
  264.         R0=0    Dormant        None
  265.         
  266.         R0=1    Starting    R1 ->Filename
  267.         
  268.         R0=2    Locating    R1 ->Filename
  269.                     R2 ->File info block (see below)
  270.                     R3 ->Frame info block (see below)
  271.                     R4 = Target time
  272.         
  273.         R0=3    Playing        R1 ->Filename
  274.                     R2 ->File info block
  275.                     R3 ->Frame info block
  276.         
  277.         R0=4    Paused        R1 ->Filename
  278.                     R2 ->File info block
  279.                     R3 ->Frame info block
  280.         
  281.         R0=5    Stopping    R1 ->Filename
  282.         
  283.         R0=6    Changing    R1 ->New filename
  284.         
  285.         R0=7    Cueing        R1 ->Filename
  286.  
  287. Note: When locating, the current time can be read from the file info block,
  288.       as it moves toward the target time returned in R4.
  289.       
  290. Note: The registers not mentioned above are preserved. This provides an easy
  291.       way of determining the info returned, without decoding R0. In Basic:
  292.       SYS "AMPlayer_Info",,"" TO ,Filename$,FIB%
  293.       This will set Filename$ to either "" or the filename. Similarily, FIB%
  294.       will be 0 if there is no info at this stage, or a pointer to it if there
  295.       is.
  296.  
  297. Note: There is a brief period when the status might be returned as 2 or 3, but
  298.       where there is no valid frame info block, because the first frame hasn't
  299.       been read. In that case, R3 will be preserved, so the code mentioned
  300.       above will still work.
  301.  
  302.  
  303. SWI AMPlayer_Control
  304. --------------------
  305. On entry    R0 = Reason code
  306.         Other registers depend on code:
  307.         R0=0    Read/write main volume
  308.             R1 = New volume (0-127), or -1 to read
  309.             On exit:
  310.             R1 = Old volume
  311.  
  312.         R0=1    Read/write size of audio buffer
  313.             R1 = New size in bytes, or -1 to read
  314.             On exit:
  315.             R1 = Old size
  316.             
  317.             If the buffer isn't currently created, this controls
  318.             how large it will be when it eventually is.
  319.             If it exists, OS_ChangeDynamicArea is used to change
  320.             the size. This may fail with an error, even if some
  321.             of the job was done (this can happen when reducing the
  322.             size, as the amount that can be released depends on
  323.             what is currently being played).
  324.             If it succeeds, the sound will be broken up at least
  325.             once. So it is best to set the size while not playing.
  326.  
  327.         R0=2    Set stack check level
  328.             R1 = New level (in words), or 0 for default
  329.             
  330.             When receiving a callback, the SVC stack depth is
  331.             checked to see if the kernel is reasonably unthreaded.
  332.             By using this call, you can control what is considered
  333.             "reasonable". The default value is currently 64, i.e.
  334.             if there are more than 64 words on the stack by the
  335.             time of the callback, a new callback will be registered
  336.             later instead. Setting this too low will cause the
  337.             player to stall, and you can only stop it by killing
  338.             the module.
  339.  
  340.  
  341. Returned structures
  342. ===================
  343.  
  344. File info block
  345. ---------------
  346. Offset    Meaning
  347. 0    Flags:
  348.     bit0 set: Total time valid
  349.     bit1 set: Elapsed time valid
  350.     bit2 set: ID3 tag info pointers valid
  351.     bit3 set: VU values valid
  352.     bit4 set: Error message pointer valid
  353.     bit5 set: Next filename pointer valid
  354.     bit6-31 reserved
  355. 4    Buffer usage ratio in %
  356. 8    Projected total time in cs if bit0 of flags set (see below)
  357. 12    Time elapsed in cs if bit1 of flags set
  358. 16    Pointer to ID3 song title if bit2 of flags set (see below)
  359. 20    Pointer to ID3 artist if bit2 of flags set
  360. 24    Pointer to ID3 album name if bit2 of flags set
  361. 28    Pointer to ID3 year string if bit2 of flags set
  362. 32    Pointer to ID3 comment if bit2 of flags set
  363. 36    Left channel VU if bit3 set (see below)
  364. 40    Right channel VU if bit3 set
  365. 44    Main volume (0..127)
  366. 48    Pointer to most recent error/warning message if bit4 of flags set
  367. 52    Pointer to filename of the "next" file if bit 5 of R0 is set
  368. 56    ID3 genre (a number) if bit2 of flags set
  369.  
  370. Note: All the string-pointers are addresses of 0-terminated strings, which are
  371.       to be read only. If you want to keep on referring to the same string,
  372.       copy it into your own workspace. The ones pointed to can and will change
  373.       according to the 'state of play'. This is not true for all of them, so
  374.       don't rely on that either (i.e. call the SWI when you want to update
  375.       your view of the current status). Also, it's important to check the
  376.       appropriate flag bit before referring to any pointers. Not doing so can
  377.       result in a program that seems to work, but fails in mysterious ways
  378.       once in a while.
  379.  
  380. Note: The projected total time is correct if the current frame type (bitrate,
  381.       etc.) stays constant until the end of the file. It will be wrong if
  382.       either
  383.       1. the file size is unknown, e.g. if playing a stream, or
  384.       2. the frame type will later change in a way that alters the number of
  385.          bytes per frame.
  386.       None of the above exceptions are true in the vast majority of mpeg files.
  387.       The first case is determined by the module, and bit0 of the flags will
  388.       be clear. The second case cannot be known in advance, and it will also
  389.       affect the elapsed time. No matter what happens, the time will always
  390.       move forward, it just might not be counting centiseconds in these cases.
  391.  
  392. Note: Any of the ID3 tag strings may be null, indeed, the often are. This
  393.       indicates that the tag field consists entirely of spaces.
  394.  
  395. Note: When the VU level is available, it is a number between 0 and 255. The
  396.       value is from -42 to 0 dB, in 1/6th dB steps. The level is the peak of
  397.       the average level since last calling this SWI.
  398.  
  399. Frame info block
  400. ----------------
  401. Offset    Meaning
  402. 0    MPEG version as 3 ASCII chars and a 0 terminator, e.g. "2.0"
  403. 4    Layer type (1..3). 0 is unknown layer
  404. 8    Sampling frequency in Hz
  405. 12    Bitrate in kbit/sec
  406. 16    Mode
  407.     0: Stereo
  408.     1: Joint-stereo
  409.     2: Dual channel
  410.     3: Single channel
  411. 20    Number of channels
  412. 24    Flags
  413.     bit0: Copyright
  414.     bit1: Original
  415.     bit2: CRC
  416. 28    Pointer to left channel DCT array
  417. 32    Pointer to right channel DCT array
  418.  
  419.  
  420. Credits
  421. =======
  422.  
  423. I have no documentation about the Audio MPEG format. So this module was
  424. produced by porting several other free mpeg decoders, extracting the
  425. necessary bits, then optimising it for RISC OS/ARM. The latter by rewriting
  426. the algorithms in most cases. Therefore, there are concepts and code bits
  427. by many different people left in this module. I will try to list the most
  428. obvious "contributors", as I could certainly not have done it without access
  429. to their work:
  430.  
  431. Michael Hipp & Oliver Fromme wrote mpg123, which was ported and used.
  432. Tomislav Uzelac wrote "amp", similarily ported and learned from.
  433. ISO MPEG Audio Subgroup Software Simulation Group, dist10 package was used
  434. as the main source of information about the intended functionality, rather
  435. than the actual implementation of it.
  436.  
  437. And thanks must go to the testers that put up with the early bugs
  438. (in order of appearance)...
  439. Gerph, Kira, unCiscy, JanM, Zhadnost, Cocodude, MoZes, Lennier, Xargle,
  440. Ben, TwoFlower, Forrey, & Nick.
  441.  
  442. License
  443. =======
  444.  
  445. I don't speak Legalese, so if any lawyers have trouble understanding the
  446. following, please ask a grownup for help.
  447.  
  448. In its current form, this is free for copying and use by anyone, subject to
  449. the following:
  450. If you want to include any of this as part of a commercial product, you need
  451. my permission.
  452. It can be freely supplied with PD, Freeware, and similar programs, as long as
  453. proper credit is given, and no money is charged for them in any way.
  454.  
  455. At some point, I will include the source, and this licence will probably be
  456. replaced with the GPL, but that will not affect the status of previous
  457. versions.
  458.  
  459.  
  460. Contact
  461. =======
  462.  
  463. Questions, etc. should be addressed to:
  464.  
  465. Thomas Olsson
  466. tolsson@isa.dknet.dk
  467.